<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="message.css">
</head>
<body>
    <style>
        #yanse{color: rgb(59, 185, 143);}
    * {
        margin: 0;
        padding: 0;
    }

    body {
        padding: 100px;
    }

    textarea {
        width: 200px;
        height: 100px;
        border: 5px rgb(51, 211, 150) solid;
        /* 不设置轮廓 */
        outline: none;
        /* 设置其不能改变长宽 */
        resize: none;
    }

    li {
        width: 300px;
        padding: 5px;
        background-color: #eee;
        font-size: 15px;
        margin: 15px 0;
    }

    li a {
        float: right;
    }
    </style>
    <div>
        <h1 id="yanse">留言板</h1>
        <ul></ul>
        <textarea placeholder="请编辑您的留言"></textarea>
        <button class="sub">发布</button>
    </div>
    <script>
        var btn=document.querySelector('.sub');
        var text=document.querySelector('textarea');
        var ul=document.querySelector('ul');

        btn.onclick=function(){
            if(text.value==''){
                alert('您没有输入内容');
                return false;
            }else{
                var li=document.createElement('li');
                li.innerHTML=text.value;
                ul.insertBefore(li,ul.children[0]);
                text.value='';
                }
        }

        var button=document.createElement('botton');
        button.className='remove';
        button.innerHTML='删除';
        button.onclick=function(){
            ul.removeChild(this.parentNode);
        }
        li.appendChild(button);
    </script>
</body>
</html>